package com.jf.net.utils;

import com.jf.net.gson.BooleanTypeAdapter;
import com.jf.net.gson.DoubleTypeAdapter;
import com.jf.net.gson.FloatTypeAdapter;
import com.jf.net.gson.GpsDoubleTypeAdapter;
import com.jf.net.gson.IntegerDefaultAdapter;
import com.jf.net.gson.ListTypeAdapter;
import com.jf.net.gson.LongDefaultAdapter;
import com.jf.net.gson.StringNullAdapter;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.List;

/**
 * 用于GSON转换格式化定制
 * @author JackyFlame
 * @time 2023/10/20 17:07
 * @description
 */
public class GsonUtil {

    public static final Gson gson = new GsonBuilder().serializeSpecialFloatingPointValues()
            .registerTypeAdapter(Integer.class, new IntegerDefaultAdapter())
            .registerTypeAdapter(String.class, new StringNullAdapter())
            .registerTypeAdapter(Boolean.class, new BooleanTypeAdapter())
            .registerTypeAdapter(Double.class, new DoubleTypeAdapter())
            .registerTypeAdapter(Float.class, new FloatTypeAdapter())
            .registerTypeAdapter(Long.class, new LongDefaultAdapter())
            .registerTypeAdapter(List.class, new ListTypeAdapter())
            .create();

    public static final Gson gsonForGPS = new GsonBuilder()
            .serializeSpecialFloatingPointValues()
            .registerTypeAdapter(Double.class, new GpsDoubleTypeAdapter())
            .create();

    private GsonUtil(){}
}
